﻿using Microsoft.AspNetCore.Http;
using Models.Common;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace UtilsBase
{
    public static class UtilsCookieSession
    {
        public static void SetCookies(this HttpContext httpContext, string key, string value, int minutes = 60 * 24 * 360)
        {
            httpContext.DeleteCookies(key);
            httpContext.Response.Cookies.Append(key, value, new CookieOptions
            {
                //过期时间
                Expires = DateTime.Now.AddMinutes(minutes)

            });
        }
        public static void DeleteCookies(this HttpContext httpContext, string key)
        {
            httpContext.Response.Cookies.Delete(key);
        }

        public static string GetCookiesValue(this HttpContext httpContext, string key)
        {
            string value = null;
            try
            {
                httpContext.Request.Cookies.TryGetValue(key, out value);
            }
            catch
            {

            }
            return value;
        }


    }
}
